package org.alerve.android.resourcebuilder;

import java.lang.reflect.Field;

import org.alerve.android.resourcebuilder.AbstractDirector.Modules;
import org.alerve.android.resourcebuilder.fieldmodules.SpinnerFieldModule;

import android.content.Context;

/**
 * 
 * Implementation of {@link AbstractDirector} that is used with the fields of an
 * object to provide extra initialisation options for it.
 * 
 * This director is used by {@link ModuleDirector} to further initialise fields
 * in an object.
 * 
 * @author pabs87@gmail.com
 * 
 * @see SpinnerFieldModule
 * 
 */
@Modules({SpinnerFieldModule.class})
public class FieldModuleDirector extends AbstractDirector<IFieldModule<?>> {

	private static FieldModuleDirector instance;

	public static FieldModuleDirector getInstance() {
		if (instance == null) {
			instance = new FieldModuleDirector();
		}
		return instance;
	}

	@SuppressWarnings("unchecked")
	public <Type> void build(Context context, Type object, Field field) {
		IFieldModule<Type> builder = (IFieldModule<Type>) getModule(object
				.getClass());
		builder.build(context, object, field);
	};

}
